Grokking System Design Fundamentals
Rate this course
Ask Author
Contribute
Back to course home

85% completed

Vote For New Content
System Design Fundamentals
Introduction to System Design
Load Balancing
Introduction to Load Balancing
Load Balancing Algorithms
Uses of Load Balancing
Load Balancer Types
Stateless vs. Stateful Load Balancing
High Availability and Fault Tolerance
Scalability and Performance
Challenges of Load Balancers
API Gateway
Introduction to API Gateway
Usage of API gateway
Advantages and disadvantages of using API gateway
Key Characteristics of Distributed Systems
Scalability
Availability
Latency and Performance
Concurrency and Coordination
Monitoring and Observability
Resilience and Error Handling
Fault Tolerance vs. High Availability
Network Essentials
HTTP vs. HTTPS
TCP vs. UDP
HTTP: 1.0 vs. 1.1 vs 2.0 vs. 3.0
URL vs. URI vs. URN
Domain Name System (DNS)
Introduction to DNS
DNS Resolution Process
DNS Load Balancing and High Availability
Caching
Introduction to Caching
Why is Caching Important?
Types of Caching
Cache Replacement Policies
Cache Invalidation
Cache Read Strategies
Cache Coherence and Consistency Models
Caching Challenges
Cache Performance Metrics
CDN
What is CDN?
Origin Server vs. Edge Server
CDN Architecture
Push CDN vs. Pull CDN
Data Partitioning
Introduction to Data Partitioning
Partitioning Methods
Data Sharding Techniques
Benefits of Data Partitioning
Common Problems Associated with Data Partitioning
Proxies
What is a Proxy Server?
Uses of Proxies
VPN vs. Proxy Server
Redundancy and Replication
What is Redundancy?
What is Replication?
Replication Methods
Data Backup vs. Disaster Recovery
CAP & PACELC Theorems
Introduction to CAP Theorem
Components of CAP Theorem
Trade-offs in CAP Theorem
Examples of CAP Theorem in Practice
Beyond CAP Theorem
System Design Trade-offs in Interviews
Databases (SQL vs. NoSQL)
Introduction to Databases
SQL Databases
NoSQL Databases
SQL vs. NoSQL
ACID vs BASE Properties
Real-World Examples and Case Studies
SQL Normalization and Denormalization
In-Memory Database vs. On-Disk Database
Data Replication vs. Data Mirroring
Database Federation
Indexes
What are Indexes?
Types of Indexes
Bloom Filters
Introduction to Bloom Filters
Benefits & Limitations of Bloom Filters
Variants and Extensions of Bloom Filters
Applications of Bloom Filters
Long-Polling vs. WebSockets vs. Server-Sent Events
Difference Between Long-Polling, WebSockets, and Server-Sent Events
Quorum
What is Quorum?
Heartbeat
What is Heartbeat?
Checksum
What is Checksum?
Uses of Checksum
Leader and Follower
What is Leader and Follower Pattern?
Security
What is Security and Privacy?
What is Authentication?
What is Authorization?
Authentication vs. Authorization
OAuth vs. JWT for Authentication
What is Encryption?
What are DDoS Attacks?
Distributed Messaging System
Introduction to Messaging System
Introduction to Kafka
Messaging patterns
Popular Messaging Queue Systems
RabbitMQ vs. Kafka vs. ActiveMQ
Scalability and Performance
What is a Distributed File System?
Architecture of a Distributed File System
Key Components of a DFS
Batch Processing vs. Stream Processing
XML vs. JSON
Synchronous vs. Asynchronous Communication
Push vs. Pull Notification Systems
Microservices vs. Serverless Architecture
Message Queues vs. Service Bus
Stateful vs. Stateless Architecture
Event-Driven vs. Polling Architecture
Quiz
Messaging patterns

In distributed systems, messaging patterns define how components communicate via asynchronous messages. Understanding these patterns is crucial for designing scalable and reliable systems. Below, we cover five key messaging patterns, each with its core idea, characteristics, and practical examples.

1. Point-to-Point (Direct Messaging)

In a point-to-point pattern, each message is delivered to exactly one consumer. A producer sends messages into a queue (or similar channel), and one of the consumers reading from that queue will receive each message. This ensures no two consumers process the same message.

  • How it works: The message broker (e.g., RabbitMQ, Amazon SQS, JMS) routes each message to a single target queue. Consumers (possibly many) compete for messages from that queue, but each message is consumed by only one of them (often called competing consumers model).
  • Core characteristics: Ensures one-consumer-per-message, enabling load balancing across workers. The queue can buffer messages if consumers are busy, providing back-pressure and reliability. Order is usually FIFO (first-in-first-out) per queue, unless priority or other ordering is configured.
  • Use case: Useful for task distribution and work queues. For example, an image processing service might place jobs on a queue so that each job is picked up by one processing worker. This way, multiple workers can parallelize tasks without duplicating work.
  • Technologies: Implemented by nearly all message queue systems. RabbitMQ and ActiveMQ have queues for this pattern; Kafka achieves a similar one-consumer-per-message effect using a single consumer group (each message in a topic partition goes to one member of the group).

2. Publish-Subscribe (Pub/Sub)

The publish-subscribe pattern delivers each message to all interested subscribers. A publisher sends messages to a topic (or exchange), and multiple subscribers receive a copy of each message. Publishers and subscribers are decoupled — the publisher doesn’t know who receives the message.

  • How it works: The message broker (e.g., Kafka, RabbitMQ, Google Pub/Sub) broadcasts published messages to all queues or subscribers that have subscribed to the topic. In RabbitMQ, a fanout or topic exchange will forward messages to multiple queues (one per subscriber). In Kafka, each subscriber group that reads a topic gets its own copy of the message.
  • Core characteristics: One-to-many distribution. Every subscriber processes the message independently. This is great for event-driven architectures where an event (message) triggers different actions in different services. Publishers and consumers are loosely coupled – you can add new consumers without changing the publisher.
  • Use case: Useful when the same event needs to be acted on in different ways. For example, when a new user registers on a platform, a “User Registered” event might be published. Multiple subscribers can react: one service sends a welcome email, another logs the signup for analytics, and another updates a recommendation model. All get the event in parallel.
  • Technologies: Kafka is inherently a pub/sub system (topics with multiple consumer groups). RabbitMQ supports pub/sub via exchanges + queues (e.g., a fanout exchange sends to all bound queues). Cloud services like AWS SNS + SQS or Azure Service Bus Topics/Subscriptions are designed for pub/sub. Ensure subscribers are configured to handle the message flow (or else messages might be dropped if a subscriber isn’t listening and the broker doesn’t persist them).

3. Request-Reply (Request-Response)

The request-reply pattern is a two-part message exchange: a requester sends a message and expects a response message in return. It’s analogous to a function call or API request, but implemented asynchronously through messaging. This pattern allows a form of synchronous interaction on top of an asynchronous system.

  • How it works: The requester sends a request message (often into a point-to-point queue or directly to a specific service). Along with the request, it provides a return address (reply queue/topic) or a callback mechanism. The consuming service (replier) processes the request and sends back a reply message to the specified reply address. A correlation ID is usually included in both messages so the requester can match the reply to its original request.
  • Core characteristics: Enables two-way communication using messaging. Decouples the request and response in time — the requester can continue other work or handle other messages while waiting for the response. Requires correlation handling in application logic to match responses. Typically involves timeouts or retries in case a reply doesn’t arrive.
  • Use case: Useful when a service needs data or action from another service but you want to avoid tight coupling of direct calls. For example, a web service might enqueue a “generate report” request to a reporting microservice and continue. The reporting service eventually sends back a report ready message. The client receives the reply and then, say, notifies the user. In system design interviews, this pattern often comes up when designing async APIs or RPC over messaging.
  • Technologies: No single broker primitive does full request-reply automatically; it’s usually implemented at the application level. RabbitMQ supports a reply-to pattern (temporary reply queues) and correlation IDs via message headers. JMS messaging has request/reply helpers. With Kafka, one could use a dedicated reply topic partition and include a correlation key. Tools like RPC frameworks (gRPC) are direct request-response (not message-based), but in messaging systems you implement this pattern explicitly.

4. Fan-Out/Fan-In (Scatter-Gather)

Fan-Out/Fan-In (also known as Scatter-Gather) is a composite pattern where a message is scattered to multiple recipients in parallel (fan-out), and then the results are gathered back (fan-in). Essentially, one request triggers multiple parallel processes and an aggregator collects all the responses or outcomes.

  • How it works (Fan-Out): A component (dispatcher) takes an incoming message or request and duplicates or distributes it to multiple consumers or services. This could be done by publishing to a topic that multiple services subscribe to, or by sending individual point-to-point messages to several target queues. Each target processes the message independently.
  • How it works (Fan-In): Another component (aggregator) waits for responses from all the scattered requests (or a certain number of them, or a timeout). Once the responses arrive, the aggregator combines the results or otherwise processes them to form a single output. The aggregated result might be sent back to the original requester or trigger the next step.
  • Core characteristics: Achieves parallelism for potentially faster overall processing time when multiple independent tasks can run concurrently. Requires handling of partial failures or slow responders (e.g., using timeouts or default values if some responses don’t come). The aggregator needs logic to correlate multiple responses to the original request (similar to correlation ID, but tracking multiple sub-responses).
  • Use case: Common in scenarios like search or aggregation services. For example, a search query in a distributed search system can be fanned-out to multiple shard servers; each shard returns results which are then merged (fan-in) before returning the final combined result to the user. Another example is an analytics job that splits work into sub-tasks (map-reduce style) across many workers and then collects the results.
  • Technologies: This pattern is implemented at the architecture level. Message brokers help with the fan-out (e.g., using pub/sub topics to broadcast requests to multiple workers). The fan-in typically requires an aggregator service or function. Some frameworks (like Apache Camel or Azure Durable Functions) provide built-in support for scatter-gather, handling the collection of responses. When using raw messaging, you’d implement a coordinating service that sends out messages and listens for replies on a dedicated channel for aggregation.

5. Dead Letter Queue (DLQ)

A Dead Letter Queue is a safety net for messages that cannot be processed successfully. When a message continually fails processing (due to errors, format issues, or exceeding retry limits), it is moved to a special queue called the Dead Letter Queue instead of being lost or blocking the main queue. This pattern ensures problematic messages are isolated for later inspection or remediation.

  • How it works: Most message systems allow configuring a DLQ for each queue or topic. If a message is rejected by a consumer, or if it exceeds a maximum number of processing attempts, the broker reroutes it to the DLQ. The DLQ is essentially a holding area for “poison messages” (messages that consistently cause failures). They remain there until they are manually reviewed or automatically processed by some error-handling service.
  • Core characteristics: Improves system resilience and reliability by not discarding failed messages immediately. Prevents blocked queues – one bad message won’t jam the processing pipeline since it gets shunted to the DLQ. Typically accompanied by monitoring/alerts, because the presence of messages in a DLQ indicates issues that need attention. It’s a passive pattern (only used on failure) but critical for robust messaging setups.
  • Use case: Any critical system with asynchronous processing should use DLQs as a best practice. For instance, in an order processing system, if an order message has corrupt data and the order service throws exceptions every time it tries that message, after a few retries the message goes to the Dead Letter Queue. This allows the system to continue with other orders, and later the faulty message can be examined or fixed without data loss.
  • Technologies: Nearly all enterprise messaging systems support DLQs. In RabbitMQ, you set a Dead Letter Exchange on a queue to route failed messages to a dead-letter queue. Kafka doesn’t have a built-in DLQ mechanism at the broker level, but patterns using separate “error topics” are used (for example, consumers or Kafka Streams can send bad records to a designated dead-letter topic). AWS SQS and Azure Service Bus both natively support DLQs with configurable retry thresholds. The key is configuring the threshold for moving to DLQ (e.g., after 5 failed attempts) and ensuring someone or something processes or monitors the DLQ.
Introduction to Kafka
Popular Messaging Queue Systems
Mark as Completed

On this page

  1. Point-to-Point (Direct Messaging)
  1. Publish-Subscribe (Pub/Sub)
  1. Request-Reply (Request-Response)
  1. Fan-Out/Fan-In (Scatter-Gather)
  1. Dead Letter Queue (DLQ)